package com.jm.weibo.db;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

/**
 * 保存用户登陆信息
 * @author Administrator
 *
 */
public class SaveUserLoginParam {
   
	/**
	 * 保存用户登陆信息
	 * @param context 上下文句柄
	 * @param username 用户名(emial)
	 * @param password 登陆密码
	 */
	public static void saveUserLoginParam(Context context, String username, String password){
	   SharedPreferences sharedPreferences = context.getSharedPreferences("loginparam", Activity.MODE_PRIVATE);
	   sharedPreferences.edit().putString("username", username)
	                           .putString("password", password)
	                           .commit();
	}
	
	/**
	 * 获取登录用户信息
	 * @param context 上下文句柄
	 * @return
	 */
	public static String[] getUserLoginParam(Context context){
		SharedPreferences sharedPreferences = context.getSharedPreferences("loginparam", Activity.MODE_PRIVATE);
		String[] params = new String[2];
		try {
			params[0] = sharedPreferences.getString("username", null);
			params[1] = sharedPreferences.getString("password", null);
		} catch (Exception e) {
			 Log.e("ERROR", "数据库中找不到可用的记录");
			 e.printStackTrace();
		}
	
		return params;
	}
}
